package com.zhengxyou.jetpackdemo.navigation;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zhengxyou.jetpackdemo.R;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;

public class TwoFragment extends Fragment {
    private String TAG = "TAG";
    private String from;
    private int intergerData;
    private TextView tv_shared;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TwoFragmentArgs args = TwoFragmentArgs.fromBundle(getArguments());
        Log.e(TAG, args.getFrom());
        Log.e(TAG, args.getIntergerData() + "");
        from = args.getFrom();
        intergerData = args.getIntergerData();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tv_shared = view.findViewById(R.id.tv_shared);
        view.findViewById(R.id.btn_next).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Navigation.findNavController(v).navigate(R.id.action_twoFragment_to_nav_include);
            }
        });
        tv_shared.setText(from + "\n" + intergerData);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_two, container, false);
    }
}
